package client;

import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.StringReader;
import java.io.StringWriter;
import java.net.Socket;
import java.net.UnknownHostException;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.InputSource;

import shared.Stringable;
import shared.XMLRMIException;

/**
 * @author Maxime Bozec 2800801
 * @author Steven Vervey 3156764
 * @version 1.0
 *
 */
public class client {

	/**
	 * Exemple of client
	 * @param args
	 * 		The port and the adress of the server
	 */
	public static void main(String[] args) {

		Integer port = 18000;
		String adresse = new String("localhost");

		if(args.length >= 1){
			port = new Integer(args[0]);
		}

		if(args.length >= 2){
			adresse = new String(args[1]);
		}



		//Creation de la socket et connexion au serveur
		try {
			Socket s = new Socket(adresse, port);

			System.out.println("Client : Connecte au serveur");
			System.out.println("-----------------------------");


			XMLRMIClientRequest cr = new XMLRMIClientRequest(s.getInputStream(), s.getOutputStream());
			
			cr.setMethodName("display");
			
			Point2 pt2 = new Point2(10);
			//cr.addParameter(pt2, Stringable.class);
			cr.addParameter(3);
			
			cr.start();

			s.close();

		}catch(UnknownHostException e){
			System.err.println("Erreur lors de la creation de la socket");
			e.printStackTrace();
			return;
		} catch (XMLRMIException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}	
	}

}
